<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  	<head>
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    	<title>Date</title>
    	<script type="text/javascript">
      		window.onload = testDate();

      		function testDate() {
        		// 创建日期的几种方式
        		var date1 = new Date();
        		document.write(date1 + "<br/>");

        		var date2 = new Date("19 July 2014");
        		document.write(date2 + "<br/>");

        		// 月份要减一
        		var date3 = new Date(2014, 6, 19, 10, 00, 00, 00);
        		document.write(date3 + "<br/>");

        		// 日期常用的方法
		        var today = new Date();
		        document.write(today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() + "<br/>");
		        document.write(today.toDateString() + "<br/>");
		        document.write("星期" + today.getDay() + "<br/>");
		
		        today.setFullYear(1984);
		        today.setMonth(4);
		        today.setDate(24);
		        document.write(today.toDateString() + "<br/>");
		        // today.setDate(32);不会发生错误, 如果当前日期为一月, 则日期设置为二月一日
		        // today.setMonth(12);不会发生错误, 如果当前为2014年1月, 则日期设置为2015年1月
	
		        var nextDate = new Date();
		        document.write("Current date " + nextDate.toDateString() + "<br/>");
		        var currentDate = nextDate.getDate();
		        // 计算从现在开始28天后的日期
		        nextDate.setDate(currentDate + 28);
		        document.write("28 days later... " + nextDate.toDateString() + "<br/>");
		
		        nextDate = new Date();
		        currentDate = nextDate.getDate();
		        // 计算当前日期之前第28天的日期
		        nextDate.setDate(currentDate - 28);
		        document.write("28 days before... " + nextDate.toDateString() + "<br/>")
      		}
    	</script>
  	</head>
  	<body>
  	</body>
</html>
